package com.tool_stdy.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


/**
 * 去除lock为什么会有脏读问题？
 * Created by yan_li on 2016/11/12.
 */
public class UnsafeThread {

	static volatile int a = 0;
	static  int b = 0;

	public static void main(String[] args) throws InterruptedException {
		 final Lock lock = new ReentrantLock();
	   for(int i=0;i<3;i++){
		   	new Thread(new Runnable() {
				@Override
				public void run() {
					lock.lock();
					for(int j = 0;j<100;j++){
						b=b+1;
						System.out.println(Thread.currentThread().getName()
								+ "--" + b);
					}
					lock.unlock();
				}
			}).start();
	   }
	   
	  Thread.sleep(200);
	  System.out.println(b);
	   
	}

}
